import { initTiming } from './timing.js'
import { behavior } from './behavior.js'
import { initSend } from './sendReports.js'
import { jsError } from './jsError.js'
import { reportingMethod } from './reportingMethod.js'
import _config from '../config/index.js'
import _U from '../utils/index.js'

export function initMonitor(MonitorSdk) {
  MonitorSdk.prototype._init = function (options) {
    try {
      // 合并默认配置
      this._CONFIG = {
        ..._config.DEFAULT_CONFIG,
        ...options
      }
      const isPerformanceFlag = this._CONFIG['performance']
      const isBehaviorFlag = this._CONFIG['behavior']
      const isJsErrorFlag = this._CONFIG['js_error']
      this.sendInfo = _config.REPORT_CONFIG
      let _this = this
      let { ProxyInfo } = _U
      let _set_ = new ProxyInfo()
      //初始化图片打点请求
      initSend(_this)
      initTiming(_this, isPerformanceFlag, _set_)
      behavior(_this, isBehaviorFlag, _set_)
      jsError(_this, isJsErrorFlag, _set_)
      reportingMethod(_this, _set_)
    } catch (error) {
      console.error('sdk:'+error,'请检查环境相关配置');
    } 
  }
}
export default initMonitor
